package edu.cuit.project.domain;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;

/**
 * Expertteam entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "expertteam", catalog = "db_project")
public class Expertteam implements java.io.Serializable {

	// Fields

	private String id;
	private String name;
	private String buildtime;
	private String leaderId;
	private Integer leaderType;
	private Set<Project> projects = new HashSet<Project>(0);
	private Set<Expert> experts = new HashSet<Expert>(0);

	// Constructors

	/** default constructor */
	public Expertteam() {
	}

	/** full constructor */
	public Expertteam(String name, String buildtime, String leaderId,
			Integer leaderType, Set<Project> projects, Set<Expert> experts) {
		this.name = name;
		this.buildtime = buildtime;
		this.leaderId = leaderId;
		this.leaderType = leaderType;
		this.projects = projects;
		this.experts = experts;
	}

	// Property accessors
	@GenericGenerator(name = "generator", strategy = "uuid")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 36)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "name", length = 30)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "buildtime", length = 30)
	public String getBuildtime() {
		return this.buildtime;
	}

	public void setBuildtime(String buildtime) {
		this.buildtime = buildtime;
	}

	@Column(name = "leader_id", length = 36)
	public String getLeaderId() {
		return this.leaderId;
	}

	public void setLeaderId(String leaderId) {
		this.leaderId = leaderId;
	}

	@Column(name = "leader_type")
	public Integer getLeaderType() {
		return this.leaderType;
	}

	public void setLeaderType(Integer leaderType) {
		this.leaderType = leaderType;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "expertteam")
	public Set<Project> getProjects() {
		return this.projects;
	}

	public void setProjects(Set<Project> projects) {
		this.projects = projects;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "expert_and_team", catalog = "db_project", joinColumns = { @JoinColumn(name = "expertteam_id", updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "expert_id", updatable = false) })
	public Set<Expert> getExperts() {
		return this.experts;
	}

	public void setExperts(Set<Expert> experts) {
		this.experts = experts;
	}

	public void addExpert(Expert expert) {
		this.experts.add(expert);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Expertteam other = (Expertteam) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}